const Ws=require('ws');

;((Ws)=>{
    //ws:localhost:8000
const server=new Ws.Server({port:8000});

const init =()=>{
bindEvent();
}
function bindEvent(){
    server.on('open',handleOpen);
    server.on('close',handleClose);
    server.on('error',handleError);
    server.on('connection',handleConnection);
}
function handleOpen(){
console.log('wsopen')
}
function handleClose(){
    console.log('wsclose')
}
function handleError(){
    console.log('wserror')
}
function handleConnection(ws){
ws.on('message',handleMessage);
}
function handleMessage(msg){
server.clients.forEach(function(c){
    c.send(msg);

})
}


init();
})(Ws);